package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.PageInfo;
import com.yyb.common.Result;
import com.yyb.domain.SysLoginInfo;
import com.yyb.dto.*;
import com.yyb.enums.BusinessType;
import com.yyb.enums.ResultEnums;
import com.yyb.service.SysLoginInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 
 * 
 * 
 */
@RestController
@RequestMapping("sysLoginInfo")
@Tag(name = "登录日志相关接口")
public class SysLoginInfoController extends BaseController {


    @Resource
    private SysLoginInfoService sysLoginInfoService;

    /**
     * 分页查询登录日志
     * POST http://127.0.0.1:8080/sysLoginInfo/getByPage
     * 接口ID：148742213
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742213
     */
    @PostMapping("getByPage")
    @Operation(summary = "分页查询登录日志")
    public Result<PageInfo<SysLoginInfo, SysLoginInfoQueryDTO>> getByPage(@RequestBody PageInfo<SysLoginInfo, SysLoginInfoQueryDTO> pageInfo) {
        PageInfo<SysLoginInfo, SysLoginInfoQueryDTO> info = this.sysLoginInfoService.getByPage(pageInfo);
        return new Result<>(info);
    }

    /**
     *根据ID删除登录日志
     *   DELETE http://127.0.0.1:8080/sysLoginInfo/delete/{loginInfoId}
     *   接口ID：148742216
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742216
     */
    @DeleteMapping("delete/{loginInfoId}")
    @Operation(summary = "根据ID删除登录日志")
    @AppPermission("system:loginInfo:remove")
    @Log(title = "登录日志-删除一个",businessType = BusinessType.DELETE)
    public Result<?> delete(@PathVariable Long loginInfoId) {
        int row = this.sysLoginInfoService.deleteByPrimaryKey(loginInfoId);
        return this.toAjax(row>0);
    }

    /**
     * 批量删除登陆日志
     *   DELETE http://127.0.0.1:8080/sysLoginInfo/batchDelete/{ids}
     *   接口ID：148742231
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742231
     * @param loginInfoIds
     * @return
     */
    @DeleteMapping("batchDelete/{loginInfoIds}")
    @Operation(summary = "批量删除登陆日志")
    @AppPermission("system:loginInfo:batchRemove")
    @Log(title = "登录日志-批量删除",businessType = BusinessType.DELETE)
    public Result<?> batchDelete(@PathVariable Long[] loginInfoIds) {
        if(loginInfoIds==null|| loginInfoIds.length==0){
            return new Result<>(ResultEnums.ERROR);
        }
        int row = this.sysLoginInfoService.deleteByPrimaryKeys(loginInfoIds);
        return this.toAjax(row>0);
    }

    /**
     * 清空登陆日志
     *   DELETE http://127.0.0.1:8080/sysLoginInfo/cleanLogininfor
     *   接口ID：148742232
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742232
     */
    @DeleteMapping("cleanLogininfor")
    @Operation(summary = "清空登陆日志")
    @AppPermission("system:loginInfo:clean")
    @Log(title = "登录日志-清空",businessType = BusinessType.DELETE)
    public Result<?> cleanLogininfor() {
        int row = this.sysLoginInfoService.deleteAllLoginInfo();
        return this.toAjax(row>0);
    }

}
